﻿using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading.Tasks;

namespace CodeAngel.Domain
{
    #region DomainDataServiceClient
    
    /// <summary>
    /// Client-side proxy class for the DomainDataService
    /// </summary>
    public partial class DomainDataServiceClient : ClientBase<IDomainDataService>, IDomainDataService
    {
        #region Create
        
        public static DomainDataServiceClient Create()
        {

            var HttpTransport = new HttpTransportBindingElement();
            HttpTransport.MaxReceivedMessageSize = int.MaxValue;
            HttpTransport.MaxBufferSize = int.MaxValue;
            var BinaryEncoding = new BinaryMessageEncodingBindingElement();
            var ThisBinding = new CustomBinding(BinaryEncoding, HttpTransport);
            var ThisEndpointAddress = new EndpointAddress("http://localhost:15402/DomainDataService.svc");
            return new DomainDataServiceClient(ThisBinding, ThisEndpointAddress);
        }

        #endregion

        #region Instance

        /// <summary>
        /// Provides access to a single instance of this DomainDataServiceClient.
        /// </summary>
        /// <returns></returns>
        public static DomainDataServiceClient Instance
        {
            get
            {
                if (_instance == null) _instance = DomainDataServiceClient.Create();
                return _instance;
            }
        }
        private static DomainDataServiceClient _instance;
        
        #endregion

        #region Constructors

        public DomainDataServiceClient()
        {
        }

        public DomainDataServiceClient(string endpointConfigurationName) :
            base(endpointConfigurationName)
        {
        }

        public DomainDataServiceClient(string endpointConfigurationName, string remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }

        public DomainDataServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }

        public DomainDataServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
            base(binding, remoteAddress)
        {
        }

        #endregion

        #region GetDtoHost

        public DtoHost GetDtoHost(string aggregateType, string filter, string userName, string password)
        {
            return base.Channel.GetDtoHost(aggregateType, filter, userName, password);
        }

        public Task<DtoHost> GetDtoHostAsync(string aggregateType, string filter, string userName, string password)
        {
            return base.Channel.GetDtoHostAsync(aggregateType, filter, userName, password);
        }

        #endregion

        #region Save

        public DtoHost Save(string aggregateType, DtoHost dtoHost, string userName, string password)
        {
            return base.Channel.Save(aggregateType, dtoHost, userName, password);
        }

        public Task<DtoHost> SaveAsync(string aggregateType, DtoHost dtoHost, string userName, string password)
        {
            return base.Channel.SaveAsync(aggregateType, dtoHost, userName, password);
        }

        #endregion

        #region Delete

        public void Delete(string aggregateType, Guid id, string userName, string password)
        {
            base.Channel.Delete(aggregateType, id, userName, password);
        }

        public Task DeleteAsync(string aggregateType, Guid id, string userName, string password)
        {
            return base.Channel.DeleteAsync(aggregateType, id, userName, password);
        }

        #endregion

        #region GetNextFriendlyID

        public int GetNextFriendlyID(string entityName)
        {
            return base.Channel.GetNextFriendlyID(entityName);
        }

        public Task<int> GetNextFriendlyIDAsync(string entityName)
        {
            return base.Channel.GetNextFriendlyIDAsync(entityName);
        }

        #endregion
    }
    
    #endregion

    #region IDomainDataService

    [ServiceContract]
    public interface IDomainDataService
    {
        [OperationContract]
        DtoHost GetDtoHost(string aggregateType, string filter, string userName, string password);

        [OperationContract]
        Task<DtoHost> GetDtoHostAsync(string aggregateType, string filter, string userName, string password);

        [OperationContract]
        DtoHost Save(string aggregateType, DtoHost dtoHost, string userName, string password);

        [OperationContract]
        Task<DtoHost> SaveAsync(string aggregateType, DtoHost dtoHost, string userName, string password);

        [OperationContract]
        void Delete(string aggregateType, Guid id, string userName, string password);

        [OperationContract]
        Task DeleteAsync(string aggregateType, Guid id, string userName, string password);

        [OperationContract]
        int GetNextFriendlyID(string entityName);

        [OperationContract]
        Task<int> GetNextFriendlyIDAsync(string entityName);
    }

    #endregion

    #region IDomainDataServiceChannel

    public interface IDomainDataServiceChannel : IDomainDataService, System.ServiceModel.IClientChannel
    {
    }

    #endregion
}
